﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using N2.Definitions;

namespace FlexiCommerce.Web.Store.Addons.FlexiCommerce.Definitions
{
    public class DenyChildAttribute : N2.Integrity.TypeIntegrityAttribute, IInheritableDefinitionRefiner 
    {
        private Type childType = null;
        public DenyChildAttribute(Type childType)
        {
            this.childType = childType;
        }

        public override void Refine(N2.Definitions.ItemDefinition currentDefinition, IList<N2.Definitions.ItemDefinition> allDefinitions)
        {
            ItemDefinition definition = (from d in allDefinitions where d.ItemType == childType select d).SingleOrDefault();
            if(definition != null)
            {
                currentDefinition.RemoveAllowedChild(definition);
            }    
        }


    }
}
